﻿using UnityEngine;
using System.Collections;
using System;

/// <summary>
/// 瞬发技能
/// </summary>
public class promptSkill : Skill
{
    TimerMaster.Timer timer = null;
    TimerMaster.Timer timer2 = null;
    public promptSkill(Actor master) : base(master)
    {
        //吟唱时间为0
        castTime = 0;
    }

    public override bool doSkill()
    {
        if (before())
        {
            state = skillState.BEFORE;
            master.controller.workArmature(armatureName, beforeCast + afterCast);
            timer2 = TimerMaster.setTimeout(_after, (int)((beforeCast + afterCast) * 1000));
            timer = TimerMaster.setTimeout(() =>
            {
                work();
                state = skillState.AFTER;
            }, (int)(beforeCast * 1000));
        }
        return true;
    }

    /// <summary>
    /// 在技能释放之前执行
    /// </summary>
    /// <returns>返回false取消</returns>
    public virtual bool before()
    {
        return true;
    }

    /// <summary>
    /// 技能释放时执行
    /// </summary>
    public virtual void work()
    {

    }

    private void _after()
    {
        after();
        state = skillState.STOP;
    }

    /// <summary>
    /// 在技能释放之后执行
    /// </summary>
    public virtual void after()
    {
    }

    public override bool stop()
    {
        if (timer != null)
        {
            TimerMaster.clearInterval(timer);
        }
        if (timer2 != null)
        {
            TimerMaster.clearInterval(timer2);
        }
        timer = null;
        _after();
        master.controller.reset();
        return true;
    }
}
